package gui;

import collector.FileObj;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * @author dotekien
 *         Date: Mar 31, 2006
 *         Time: 5:09:38 PM
 */
public class FileTableModel extends SameTableModel {
    public static final String[] TOOL_TIPS = new String[]{
            null,
            null,
            "Number of duplicated statements", //include the percentage compared with number of statments of files
            "Number of chains",
            "Number of statements",
            "Percentage duplication on the number statements of one file"
    };
    ArrayList<FileObj> files;

    public FileTableModel(ArrayList<FileObj> files) {
        this.files = files;
        /*File view: File name(get the sorted path), how many statement is duplicated, percentage compared
with number of stat of this file. number of chunk, number of chain.*/
        columnNames = new String[]{"ID", //reflect the order in gui, not in collection
                "Files",
                "NDS",
                "NC",
                "NS",
                "Percentage",
        };

        types = new Class[]{Number.class,
                Object.class,
                Number.class,
                Number.class,
                Number.class,
                Number.class};
        fillData();
    }

    private void fillData() {
        int row = files.size();
        int col = getColumnCount();
        data = new Object[row][col];
        DecimalFormat df = new DecimalFormat("###.##");

        for (int i = 0; i < row; i++) {
            FileObj f = files.get(i);
            int nods = f.getNumberOfWarningStatement();
            int noc = f.getChunks().size();
            int nos = f.getNumberOfStatement();

            data[i][0] = i; //f.getId();
            data[i][1] = f.getPath();
            data[i][2] = nods;
            data[i][3] = noc;
            data[i][4] = nos;
            data[i][5] = new Double(df.format(100.0 * nods / nos));
        }
    }
}
